#include "MealListPanel.h"

MealListPanel::MealListPanel(MasterComponent* master, int w, int h) :
	ListPanel(master, w, h) {

	deque<Eatable>& items = PersistentFoodList::instance().getMeals();
	copy(items.begin(), items.end(), inserter(filteredItems, filteredItems.begin()));

	addAndMakeVisible(mealView = new MealView());
	showItemView(0);

	mealView->setBounds(35, 94, 5 * width / 7 - 70, height - 123);
	listBox->updateContent();

	backButton->setFromTo(MasterComponent::MEAL_LIST, MasterComponent::MAIN);
}

void MealListPanel::paint(Graphics& g) {
	Rectangle r(0, 0, width, height);
	g.setColour(Colours::palegoldenrod);
	g.fillRoundedRectangle(r, 50);
	g.setColour(Colours::grey);
	MiscGraphics::drawRoundedRect(g, r, 50, 1);

	g.setColour(Colours::black);
	g.setFont(Font(Font::getDefaultSansSerifFontName(), 36, Font::plain));
	g.drawFittedText(T("Meal List"), 0, 0, width, 100, Justification::centred, 1);

	paintListBox(g);
}

void MealListPanel::mouseDown(const MouseEvent& e) {
}

void MealListPanel::switchPanels(int from, int to) {
	master->switchPanels(from, to);
}

void MealListPanel::showItemView(int row) {
	mealView->setEatable(&filteredItems[row]);
	mealView->repaint();
}

deque<Eatable>& MealListPanel::getEatableList() {
	return PersistentFoodList::instance().getMeals();
//	return items;
}

void MealListPanel::doubleClicked(const MouseEvent& e) {

}
